package com.financing.wap.web.controller.api;



import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.financing.wap.common.ResultMap;
import com.financing.wap.common.Session;
import com.financing.wap.common.SessionUtil;
import com.financing.wap.common.ResultMap.STATUS;
import com.financing.wap.dto.ClientUserBaseDTO;
import com.financing.wap.dto.DiscussDTO;
import com.financing.wap.dto.UserDTO;
import com.financing.wap.service.IDiscussService;
import com.financing.wap.util.Constants;
import com.financing.wap.web.controller.BaseController;

@Controller("apiDiscussController")
@RequestMapping("/api/discuss")
public class DiscussController  extends BaseController{

	Logger logger = Logger.getLogger(getClass());

	@Autowired
	private IDiscussService discussService;

	/**
	 * 展示所有评论列表
	 * @return
	 */
	@RequestMapping("/list")
	@ResponseBody
	public ResultMap list(HttpServletRequest request, HttpServletResponse response){

		DiscussDTO dto = new DiscussDTO();
		ResultMap result = new ResultMap();
		try {
			List<DiscussDTO> discussList  = discussService.getDiscussDTOList(dto);
			result.setStatus(STATUS.SUCCESS);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setAttribute("discussList", discussList);
		}catch(Exception e) {
			logger.warn("==>warn messang:"+e.getMessage());
			result.setStatus(STATUS.ERROR);
		}
		return result;
	}


	/**
	 * 新增反馈
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public ResultMap addPost( HttpServletRequest request, HttpServletResponse response,DiscussDTO dto){

		ResultMap result = new ResultMap();
		try {
			Session session = SessionUtil.getSession();
			UserDTO loginUser = session.getUser();
			String faId = loginUser.getId();
			dto.setuId(faId);
			dto.setuDiscussType(Constants.DISCUSS_TYPE_03);
			dto.setCreateBy(faId.toString());
			dto.setUpdateBy(faId.toString());
			result.setStatus(STATUS.SUCCESS);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
		}catch(Exception e) {
			logger.warn("==>warn messang:"+e.getMessage());
			result.setStatus(STATUS.WARN);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	/**
	 * 新增反馈初始化
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	@ResponseBody
	public ResultMap addGet( HttpServletRequest request, HttpServletResponse response,ClientUserBaseDTO clientUserBaseDTO){
		ResultMap result = new ResultMap();
//		result.setAttribute("selectSex", SelectUtils.getSelectSex());
		return result;
	}

}
